<?php

declare(strict_types=1);

namespace App\CustHub\Controller\Admin;

use App\CustHub\Controller\BaseController;
use App\CustHub\Request\ServerRequest;
use App\CustHub\Service\ChGetUserService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Mine\Annotation\Auth;
use Mine\Annotation\OperationLog;
use Mine\Annotation\Permission;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use \Psr\Http\Message\ResponseInterface;


#[Controller(prefix: "ch/admin/chGetUser"),Auth]
class ChGetUserController extends BaseController
{
    #[Inject]
    protected ChGetUserService $service;

    /**
     * 获取用户列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[GetMapping("index"), Permission("ch:admin:chGetUser:index")]
    public function getUser(): ResponseInterface
    {
        return $this->success($this->service->getUser($this->request->all()));
    }

    /**
     * 修改备注或用户余额
     * @param int $id
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PutMapping("update/{id}"), Permission("ch:admin:chGetUser:update"), OperationLog]
    public function update(int $id): ResponseInterface
    {
        return $this->service->update($id, $this->request->all()) ? $this->success() : $this->error();
    }

    /**
     * 给用户增加席位
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping("addSeat/{id}"), Permission("ch:admin:chGetUser:addSeats"), OperationLog]
    public function addSeat(): ResponseInterface
    {
        return $this->service->addSeat($this->request->all()) ? $this->success() : $this->error();
    }
}